import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_one_time_purchased_item_transaction.dart';
import 'package:backend.core/core/domain/entities/api/google_play/api_google_play_transaction_revocation_info.dart';
import 'package:backend.core/core/domain/entities/google_play/google_play_one_time_purchased_item_transaction.dart';
import 'package:backend.purchases/domain/helpers/api/google_play/create_api_google_play_purchased_item_revocation_info_from_internal_one.dart';

abstract class CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne {
  ApiGooglePlayOneTimePurchasedItemTransaction call({
    required GooglePlayOneTimePurchasedItemTransaction transaction,
  });
}

class CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOneImpl
    implements CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOne {
  const CreateApiGooglePlayOneTimePurchasedItemTransactionFromInternalOneImpl({
    required CreateApiGooglePlayTransactionRevocationInfoFromInternalOne
        createApiGooglePlayTransactionRevocationInfoFromInternalOne,
  }) : _createApiGooglePlayTransactionRevocationInfoFromInternalOne =
            createApiGooglePlayTransactionRevocationInfoFromInternalOne;

  final CreateApiGooglePlayTransactionRevocationInfoFromInternalOne
      _createApiGooglePlayTransactionRevocationInfoFromInternalOne;

  @override
  ApiGooglePlayOneTimePurchasedItemTransaction call({
    required GooglePlayOneTimePurchasedItemTransaction transaction,
  }) {
    ApiGooglePlayTransactionRevocationInfo? apiRevocationInfo;

    if (transaction.revocationInfo != null) {
      apiRevocationInfo = _createApiGooglePlayTransactionRevocationInfoFromInternalOne(
        revocationInfo: transaction.revocationInfo!,
      );
    }

    return ApiGooglePlayOneTimePurchasedItemTransaction(
      orderId: transaction.orderId,
      promotional: transaction.promotional,
      time: transaction.time,
      revocationInfo: apiRevocationInfo,
    );
  }
}
